﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_qc_RM : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        handleEditMode();
       
    }



    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.AbsolutePath);
    }
    protected void linkEdit_Click(object sender, EventArgs e)
    {
        string id = ((LinkButton)sender).CommandArgument;
        Response.Redirect(Request.Url.AbsolutePath + "?editRecord=" + id);
    }


    protected void linkDelete_Click(object sender, EventArgs e)
    {
        string id = ((LinkButton)sender).CommandArgument;
        tbl_qc_rm model = new tbl_qc_rm();
        model.ID = Convert.ToInt32(id.ToString());

        BLL_tbl_qc_rm bll = new BLL_tbl_qc_rm();
        bll.delete(model);
    }


    protected void handleEditMode()
    {
        if (!IsPostBack)
        {

            if (Request.QueryString["editRecord"] != null)
            {

               
                string id = Request.QueryString["editRecord"];

                BLL_tbl_qc_rm bll = new BLL_tbl_qc_rm();
                List<tbl_qc_rm> list = bll.select(Convert.ToInt32(id));
                foreach (tbl_qc_rm tbl in list)
                {
                    // btnSave.CommandArgument = tbl.MESS635_ID.ToString();
                    
                    ddlRM_Order_Number.Attributes.Add("SelectedVal", tbl.RM_Order_Number);
                    ddlBag_Number.Attributes.Add("SelectedVal", tbl.Bag_Number);
                    ddlDrum_Number.Attributes.Add("SelectedVal", tbl.Drum_Number);
                    txtDate.Text = Convert.ToDateTime(tbl.Date).ToString("yyyy-MM-dd");
                    txtAl.Text = tbl.Al.ToString();
                    txtC.Text = tbl.C.ToString();
                    txtCa.Text = tbl.Ca.ToString();
                    txtFe.Text = tbl.Fe.ToString();
                    ddlGrade.SelectedValue = tbl.Grade;
                   
                  
                }
                string script = "$('#MainContent_Add_ddlRM_Order_Number').val($('#MainContent_Add_ddlRM_Order_Number').attr('selectedval'));";
                script += "getDrums();";
                script += "getBags();";
                
                ScriptManager.RegisterStartupScript(this, this.GetType(), "BindDrum", script, true);

                
            }
        }
        
    }

   
}